<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="emp" value="${sessionScope.user}"/>
<c:forEach var="ro" items="${emp.roles}">
	<c:forEach var="fu" items="${ro.functionAll}">
		<c:if test="${fu.code=='message-delete'}">
			<c:set var="mesDel"  value="true"/>
		</c:if>
		<c:if test="${fu.code=='message-put-rubbish'}">
			<c:set var="putRub"  value="true"/>
		</c:if>
	</c:forEach>
</c:forEach>
<section class="content">
	<!-- MAILBOX BEGIN -->
	<div class="mailbox row">
		<div class="col-xs-12">
			<div class="box box-solid">
				<div class="box-body">
					<div class="row">
						<div class="col-md-3 col-sm-4">
							<!-- BOXES are complex enough to move the .box-header around.
                                                 This is an example of having the box header within the box body -->
                           	<div class="box-header">
								<i class="glyphicon glyphicon-envelope"></i>
								<h3 class="box-title">写信</h3>
							</div>
                            <c:forEach var="ro" items="${emp.roles}">
                            	<c:forEach var="fu" items="${ro.functions['pageMenuItem']}">
                            		<c:if test="${fu.id==param.parentId}">
                            			<c:forEach var="child" items="${fu.pageChildren}">
                            				<c:if test="${child.code=='message-send'}">
                            					<!-- compose message btn -->
                            					<a class="btn btn-block btn-primary" data-toggle="modal"
													data-target="#compose-modal" id="writemessage">
													<i class="${child.menuLog}"></i> 
													${child.name }
												</a>
                            				</c:if>
                            			</c:forEach>
                            			<!-- Navigation - folders-->
										<div style="margin-top: 15px;">
											<ul class="nav nav-pills nav-stacked" id="message_sidebar">
												<c:forEach var="child" items="${fu.pageChildren}" varStatus="status">
		                            				<c:if test="${child.code!='message-send'}">
		                            					<c:if test="${empty param.categoryId }">
		                            						<c:if test="${status.index==0 }">
		                            							<c:if test="${child.code=='message-inbox' }">
		                            								<li class="active">
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=1">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            							<c:if test="${child.code=='message-outbox' }">
		                            								<li class="active">
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=2">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            							<c:if test="${child.code=='message-draft' }">
		                            								<li class="active">
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=0">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            							<c:if test="${child.code=='message-rubbish' }">
		                            								<li class="active">
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=5">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            						</c:if>
		                            					</c:if>
		                            					<c:if test="${not empty param.categoryId }">
		                            						<c:if test="${status.index==0 }">
		                            							<c:if test="${child.code=='message-inbox' }">
		                            								<li>
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=1">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            							<c:if test="${child.code=='message-outbox' }">
		                            								<li>
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=2">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            							<c:if test="${child.code=='message-draft' }">
		                            								<li>
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=0">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            							<c:if test="${child.code=='message-rubbish' }">
		                            								<li>
		                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=5">
		                            										<i class="${child.menuLog}"></i>
		                            										${child.name }
		                            									</a>
		                            								</li>
		                            							</c:if>
		                            						</c:if>
		                            					</c:if>
		                            					<c:if test="${child.code=='message-inbox' }">
		                            						<c:if test="${param.categoryId==1 }">
		                            							<li class="active">
		                            						</c:if>
		                            						<c:if test="${param.categoryId!=1 }">
		                            							<li>
		                            						</c:if>
                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=1">
                            										<i class="${child.menuLog}"></i>
                            										${child.name }
                            									</a>
                            								</li>
                            							</c:if>
                            							<c:if test="${child.code=='message-outbox' }">
                            								<c:if test="${param.categoryId==2 }">
		                            							<li class="active">
		                            						</c:if>
		                            						<c:if test="${param.categoryId!=2 }">
		                            							<li>
		                            						</c:if>
                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=2">
                            										<i class="${child.menuLog}"></i>
                            										${child.name }
                            									</a>
                            								</li>
                            							</c:if>
                            							<c:if test="${child.code=='message-draft' }">
                            								<c:if test="${param.categoryId==0 }">
		                            							<li class="active">
		                            						</c:if>
		                            						<c:if test="${param.categoryId!=0 }">
		                            							<li>
		                            						</c:if>
                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=0">
                            										<i class="${child.menuLog}"></i>
                            										${child.name }
                            									</a>
                            								</li>
                            							</c:if>
                            							<c:if test="${child.code=='message-rubbish' }">
                            								<c:if test="${param.categoryId==5 }">
		                            							<li class="active">
		                            						</c:if>
		                            						<c:if test="${param.categoryId!=5 }">
		                            							<li>
		                            						</c:if>
                            									<a href="${initParam.root}/${child.menuEntry}?parentId=${param.parentId}&categoryId=5">
                            										<i class="${child.menuLog}"></i>
                            										${child.name }
                            									</a>
                            								</li>
                            							</c:if>
		                            				</c:if>
		                            			</c:forEach>
											</ul>
										</div>
                            		</c:if>
                            	</c:forEach>
                            </c:forEach>    
						</div>
						<!-- /.col (LEFT) -->
						<div class="col-md-9 col-sm-8">
							<div class="row pad">
								<div class="col-sm-6">
									<!-- Action button -->
								</div>
								<div class="col-sm-6 search-form">
									<form action="message" class="text-right" method="get">
										<div class="input-group">
											<input type="text" class="form-control input-sm"
												placeholder="搜索" name="search">
											<input type="hidden" name="categoryId" value="${categoryId }">
											<div class="input-group-btn">
												<button type="submit" class="btn btn-sm btn-primary">
													<i class="fa fa-search"></i>
												</button>
											</div>
										</div>
									</form>
								</div>
							</div>
							<!-- /.row -->
							<div class="table-responsive">
								<!-- 邮箱列表 -->
								<table id="mailTabl" class="table table-mailbox">
									<tbody>
										<tr>
											<td class="subject"><i class="fa fa-star"></i></td>
											<td class="subject"><a href="#">${categoryId==1?'发件人':'收件人'}</a></td>
											<td class="subject"><a href="#">主题</a></td>
											<td class="time">时间</td>
											<td class="subject" style="padding-left:40px;">操作</td>
										</tr>
										<c:forEach var="Message" items="${MessageList }">
											<c:if test="${Message.status==0 }">
												<tr class="unread">
													<td class="small-col"><i class="fa fa-star"></i></td>
													<td class="name add-message" ref-id="${Message.id}">
														<a data-toggle="modal" data-target="#compose-modal">
															${Message.receivers}
														</a>
													</td>
													<td class="subject edit-message">
														<a data-toggle="modal" data-target="#compose-modal">
															${Message.title }
														</a>
													</td>
													<td class="time">${Message.sendTime }</td>
													<td class="name" style="padding-left:40px;">
														<c:if test="${param.categoryId==0 }">
															<button class="btn btn-primary" data-id="${Message.id}" data-level="${Message.level}" class="edit-message" data-toggle="modal" data-target="#compose-modal">编辑</button>&nbsp;&nbsp;
														</c:if>
														<c:if test="${param.categoryId==5 }">
															<c:if test="${mesDel==true}">
																<form action="delete-message" method="post">
																	<input type="hidden" name="messageId" value="${Message.id }"/>
																	<button type="submit" class="btn btn-primary">删除</button>
																</form>
															</c:if>	
														</c:if>
														<c:if test="${param.categoryId!=0&&param.categoryId!=5}">
															<c:if test="${putRub==true}">
																<form action="putIn-rubbish" method="post">
																	<input type="hidden" name="messageId" value="${Message.id }"/>
																	<button type="submit" class="btn btn-primary">移至回收站</button>
																</form>
															</c:if>	
														</c:if>
													</td>
												</tr>
											</c:if>
											<c:if test="${Message.status==1 }">
												<tr>
													<td class="small-col"><i class="fa fa-star"></i></td>
													<td class="name"><a data-toggle="modal" data-target="#compose-modal">${Message.receivers}</a></td>
													<td class="subject"><a data-toggle="modal" data-target="#compose-modal">${Message.title }</a></td>
													<td class="time">${Message.sendTime }</td>
													<td class="name"> 
														<c:if test="${param.categoryId==0 }">
															<button class="btn btn-primary" data-id="${Message.id}" data-level="${Message.level}" class="edit-message" data-toggle="modal" data-target="#compose-modal">编辑</button>&nbsp;&nbsp;
														</c:if>
														<c:if test="${param.categoryId==5 }">
															<c:if test="${mesDel==true}">
																<form action="delete-message" method="post"> 
																	<input type="hidden" name="messageId" value="${Message.id }"/>
																	<button type="submit" class="btn btn-primary">删除</button>
																</form>
															</c:if>	
														</c:if>
														<c:if test="${param.categoryId!=0&&param.categoryId!=5}">
															<c:if test="${putRub==true}">
																<form action="putIn-rubbish" method="post">
																	<input type="hidden" name="messageId" value="${Message.id }"/>
																	<button type="submit" class="btn btn-primary">移至回收站</button>
																</form>
															</c:if>	
														</c:if>
													</td>
												</tr>
											</c:if>
										</c:forEach>
									</tbody>
								</table>
							</div>
							<!-- /.table-responsive -->
						</div>
						<!-- /.col (RIGHT) -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.box-body -->
				<div class="box-footer clearfix">
					<c:if test="${categoryId==1 }">
						<div class="pull-right">
							<small>第${pageNum }页--共${totalPage}页</small>
							<c:if test="${pageNum==1}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-left"></i>
								</button>
							</c:if>
							<c:if test="${pageNum>1}">
								<a href="${initParam.root}/message-inbox?parentId=40&pageNum=${pageNum-1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-left"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum<totalPage}">
								<a href="${initParam.root}/message-inbox?parentId=40&pageNum=${pageNum+1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-right"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum==totalPage}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-right"></i>
								</button>
							</c:if>
						</div>
					</c:if>
					<c:if test="${categoryId==2 }">
						<div class="pull-right">
							<small>第${pageNum }页--共${totalPage}页</small>
							<c:if test="${pageNum==1}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-left"></i>
								</button>
							</c:if>
							<c:if test="${pageNum>1}">
								<a href="${initParam.root}/message-outbox?parentId=40&pageNum=${pageNum-1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-left"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum<totalPage}">
								<a href="${initParam.root}/message-outbox?parentId=40&pageNum=${pageNum+1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-right"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum==totalPage}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-right"></i>
								</button>
							</c:if>
						</div>
					</c:if>
					<c:if test="${categoryId==0 }">
						<div class="pull-right">
							<small>第${pageNum }页--共${totalPage}页</small>
							<c:if test="${pageNum==1}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-left"></i>
								</button>
							</c:if>
							<c:if test="${pageNum>1}">
								<a href="${initParam.root}/message-draft?parentId=40&pageNum=${pageNum-1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-left"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum<totalPage}">
								<a href="${initParam.root}/message-draft?parentId=40&pageNum=${pageNum+1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-right"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum==totalPage}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-right"></i>
								</button>
							</c:if>
						</div>
					</c:if>
					<c:if test="${categoryId==5 }">
						<div class="pull-right">
							<small>第${pageNum }页--共${totalPage}页</small>
							<c:if test="${pageNum==1}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-left"></i>
								</button>
							</c:if>
							<c:if test="${pageNum>1}">
								<a href="${initParam.root}/message-rubbish?parentId=40&pageNum=${pageNum-1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-left"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum<totalPage}">
								<a href="${initParam.root}/message-rubbish?parentId=40&pageNum=${pageNum+1}&categoryId=${categoryId}">
									<button class="btn btn-xs btn-primary">
										<i class="fa fa-caret-right"></i>
									</button>
								</a>
							</c:if>
							<c:if test="${pageNum==totalPage}">
								<button class="btn btn-xs btn-primary">
									<i class="fa fa-caret-right"></i>
								</button>
							</c:if>
						</div>
					</c:if>
				</div>
				<!-- box-footer -->
			</div>
			<!-- /.box -->
		</div> 
		<!-- /.col (MAIN) -->
	</div>
	<!-- MAILBOX END -->
</section>